package mianyang.zhangsan.com.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import mianyang.zhangsan.com.mapper.TeacherMapper;
import mianyang.zhangsan.com.pojo.Teacher;
import mianyang.zhangsan.com.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("teacherService")
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    /**
     * 根据用户名查询老师信息
     * @param username
     * @return
     */
    @Override
    public Teacher queryInfoByUsername(String username) {
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        return teacherMapper.selectOne(wrapper);
    }

    /**
     * 查询所有老师信息
     * @return
     */
    @Override
    public List<Teacher> queryInfoAll() {

        return teacherMapper.selectList(null);
    }

    /**
     * 分页查询教师信息
     * @param page
     * @param size
     * @param clazzId
     * @return
     */
    @Override
    public Page<Teacher> queryByPage(int page, int size, int clazzId) {
        QueryWrapper<Teacher> wrapper = null;
        if (clazzId != 0){
            wrapper = new QueryWrapper<>();
            wrapper.eq("clazz_id", clazzId);
        }
        return teacherMapper.selectPage(new Page<>(page, size), wrapper);
    }
}
